package
{
	public class ModBusDevice extends Object
	{
		private var Relay_0:uint=1;
		private var Relay_1:uint=1;
		private var Relay_2:uint=1;
		private var Relay_3:uint=1;
		private var Relay_4:uint=1;
		private var Relay_5:uint=1;
		private var Relay_6:uint=1;
		private var Relay_7:uint=1;
		public var id:uint=0;
		private var relays:Array=[Relay_0,Relay_1,Relay_2,Relay_3,Relay_4,Relay_5,Relay_6,Relay_7];
		public function ModBusDevice()
		{
			super();
		}
		
		public function open(target:uint):void
		{
//			trace("open is "+target);
			if(target>=relays.length)return;
			relays[target]=1;
			
		}
		
		public function close(target:uint):void
		{
//			trace("close is "+target);
			if(target>=relays.length)return;
			relays[target]=0;
			
		}
		
		public function allOpen():void
		{
			for(var i:uint=0;i<relays.length;i++)
			{
				open(i);
			}
		}
		
		
		public function allClose():void
		{
			for(var i:uint=0;i<relays.length;i++)
			{
				close(i);
			}
		}
		
		public function getResult():String
		{
			var str:String="";
			for(var i:uint=0;i<relays.length;i++)
			{
				str+=relays[i].toString();
			}
			var result:String=str;
			var arr:Array=result.split("");
			arr.reverse();
			result="";
			for(i=0;i<arr.length;i++)
			{
				result+=arr[i];
			}
			
			return result;
		}
		
	}
}